package com.hp.controller.api;

import com.hp.entity.Resources;
import com.hp.entity.ResourcesType;
import com.hp.service.ResourcesService;
import com.hp.service.ResourcesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/resource")
public class ApiResourcesController {

    @Autowired
    private ResourcesService resourcesService;


    @Autowired
    private ResourcesTypeService resourcesTypeService;
    /**
     * 资源数据
     *
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getAllResource")
    public List getAllResource() throws Exception {
        List<Resources> list = resourcesService.getAllResourceAndIsY();
        return list;
    }

    /**
     * 通过类型查看审核通过的资源
     *
     * @param typeid
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getAllResourceById")
    public List<Resources> getAllResourceById(String typeid) throws Exception {
        List<Resources> list = resourcesService
                .findAllByIdAndIsY(typeid);
        return list;
    }


    @ResponseBody
    @GetMapping("/getAllTypeResource")
    public Map getAllTypeResource() throws Exception {
        List<ResourcesType> list = resourcesTypeService.pageresourcetype(1, Integer.MAX_VALUE, null).getRows();
        Map map = new HashMap();
        map.put("data", list);
        map.put("sum", 0);
        return map;
    }

    /**
     * 查看模块详细资源+添加点击数
     *
     * @param id
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getByIdResource")
    public Resources getByIdResource(String id) throws Exception {
        Resources p = resourcesService.lookById(id);
        return p;
    }
}
